<?php
class Frontend_Table_User extends Custom_Model_Table_Abstract
{
    protected $_name        = 'user';
    protected $_rowClass    = 'Frontend_Table_Row_User';

    public function findById($id)
    {
        return $this->find((int)$id)->current();
    }

    public function findByName($name, $ignore = null)
    {
        $select = $this->select();
        $select->where('name = ?',$name);

        if (null !== $ignore) {
            $select->where('name != ?', $ignore->name);
        }
        
        return $this->fetchRow($select);
    }

    public function findByEmail($email, $ignore = null)
    {
        $select = $this->select();
        $select->where('email = ?',$email);

        if (null !== $ignore) {
            $select->where('email != ?',$ignore->email);
        }
        return  $this->fetchRow($select);
    }

    public function getAll($paged = null, $order = null)
    {
        $select = $this->select();

        if (true === is_array($order)) {
            $select->order($order);
        }

        if (null !== $paged) {
            $adapter = new Zend_Paginator_Adapter_DbTableSelect($select);
            $count = clone $select;
            $count->reset(Zend_Db_Select::COLUMNS);
            $count->reset(Zend_Db_Select::FROM);
            $count->from('user', new Zend_Db_Expr('COUNT(*) AS `zend_paginator_row_count`'));
            $adapter->setRowCount($count);
            $paginator = new Zend_Paginator($adapter);
            $paginator->setItemCountPerPage(5)
    	          	  ->setCurrentPageNumber((int) $paged);
        	return $paginator;
        }
        return $this->fetchAll($select);
    }
}
